<template>
	<view class="page">
		<view class="head-img"><image :src="userInfo.head_pic_text"></image></view>
		<button class="u-confirm" @tap="confirm">绑定微信</button>
	</view>
</template>

<script>
	import jewel from '@/common/common.js';
	export default {
		data() {
			return {
				userInfo:{}
			};
		},
        methods:{
            confirm() {
				//绑定微信
				let postData = {}
				uni.login({
					provider: 'weixin',
					success: function(res) {
						postData.union_id = res.authResult.unionid;
						uni.showLoading({
							title:'绑定中'
						})
						uni.getUserInfo({
						    provider: 'weixin',
						    success: function (infoRes) {
								postData.openid = infoRes.userInfo.openId;
								postData.nickname = infoRes.userInfo.nickName;
								postData.gender = infoRes.userInfo.gender;
								postData.head_pic = infoRes.userInfo.avatarUrl;
								jewel.post('member/bindWx',postData,true,function(res){
									uni.hideLoading()
									if (res.data.code == 0) {
										uni.showToast({
											icon:'success',
											title:res.data.msg,
											duration:500
										})
										setTimeout(()=>{
											uni.switchTab({
												url:'/pages/jewel/index/index'
											})
										},500)
									}else{
										jewel.showToast(res.data.msg);
									}
								},function(res){
									jewel.showToast('请求失败');
								});
							}
						});	
					}
				});
            },
			
        },
		onLoad(){
			this.userInfo = uni.getStorageSync('userInfo')
		}
	}
</script>

<style>
    .page {
        background: #f5f5f5;
    }
    .head-img image{
		border-radius: 50%;
		overflow: hidden;
		width: 100rpx;
		height: 100rpx;
		display: block;
		margin:10px auto;
	}
	.input{
		padding: 20rpx;
		display: flex;
		align-items: center;
	}
	.upload-img{
		background: #FFFFFF;
		display: flex;
		padding: 20rpx;
		box-sizing: border-box;
	}
	.upload-img .publish-upload{
		width: 180rpx;
		height: 180rpx;
		border: 1px solid #e6e6e6;
		background: #F5F5F5;
		border-radius: 5px;
		text-align: center;
		display: flex;
		align-items: center;
		position: relative;
		z-index: 1;
	}
	.upload-img .publish-upload:after{
		content: '';
		position: absolute;
		background-image: url('~@/static/icons/plus.png');
		background-repeat: no-repeat;
		background-size: 60rpx 60rpx;
		background-position: center center;
		top: 0;
		left: 0;
		width: 100%;
		height: 100%;
		z-index: -1;
	}
	.upload-img .publish-upload image{
		width: 100%;
		height: 100%;
		display: block;
		margin: 0 auto;
	}
	.u-confirm{
		width: 90%;
		margin: 60rpx 0 0 5%;
		border-radius: 100px;
		background: #d71611;
		color: #fff;
		text-align: center;
		line-height: 100rpx;
		font-size: 38rpx;
	}
</style>
